package com.atguigu.lease.web.app.service.impl;

import com.atguigu.lease.common.utils.JwtUtil;
import com.atguigu.lease.model.entity.BrowsingHistory;
import com.atguigu.lease.model.enums.ItemType;
import com.atguigu.lease.web.app.mapper.BrowsingHistoryMapper;
import com.atguigu.lease.web.app.mapper.GraphInfoMapper;
import com.atguigu.lease.web.app.service.BrowsingHistoryService;
import com.atguigu.lease.web.app.vo.graph.GraphVo;
import com.atguigu.lease.web.app.vo.history.HistoryItemVo;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;

import java.util.List;

/**
 * @author liubo
 * @description 针对表【browsing_history(浏览历史)】的数据库操作Service实现
 * @createDate 2023-07-26 11:12:39
 */
@Service
@Slf4j
public class BrowsingHistoryServiceImpl extends ServiceImpl<BrowsingHistoryMapper, BrowsingHistory>
        implements BrowsingHistoryService {
    @Autowired
    private BrowsingHistoryMapper browsingHistoryMapper;
    @Autowired
    private GraphInfoMapper graphInfoMapper;

    @Override
    public void  pageInfoList(IPage<HistoryItemVo> page,String token) {

        Long userId = JwtUtil.parseToken(token).get("userId", Long.class);

        IPage<HistoryItemVo> historyItemVos = browsingHistoryMapper.getHistoryInfoByUserId(page, userId);
        if (!ObjectUtils.isEmpty(historyItemVos)){
            for (HistoryItemVo itemVo : historyItemVos.getRecords()) {
                List<GraphVo> list=graphInfoMapper.graphListByItem(itemVo.getRiId(), ItemType.ROOM);
                itemVo.setRoomGraphVoList(list);
            }
        }
    }
}




